<%--
  Created by IntelliJ IDEA.
  User: 123
  Date: 2020/11/27
  Time: 20:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<div class="layui-container">
    <form class="layui-form">
        <div class="layui-row">
            <div class="layui-col-md8">
                <div class="layui-form-item">
                    <label class="layui-form-label">帖子标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="where" placeholder="请输入" autocomplete="off" class="layui-input" id="c">
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <button class="layui-btn" lay-submit lay-filter="go" id="cd">搜索</button>
            </div>
        </div>
    </form>
</div>
</div>
<table id="demo" lay-filter="test" ></table>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
<script>
    layui.use(['table','form'], function () {
        var table = layui.table;
        var form=layui.form;
        //第一个实例
        table.render({
            elem: '#demo'
            , url: 'Invitations' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'id', title: '帖子编号'}
                , {field: 'title', title: '贴在标题'}
                , {field: 'summary', title: '帖子摘要'}
                , {field: 'author', title: '作者'}
                , {field: 'createdate', title: '发布时间'}
                , {title: '操作', toolbar: '#barDemo'}
            ]]
        });
        form.on('submit(go)', function(data){
           var date=data.field;
           console.log(date)
            if (date!=undefined){
                table.reload('demo', {
                    url: "Invitationss"
                    ,where:date
                });
            }
            return false;
        });
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if(layEvent === 'detail'){ //查看
                location="reply.jsp";
            } else if(layEvent === 'del'){ //删除
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if(layEvent === 'edit'){ //编辑
                //do something

                //同步更新缓存对应的值
                obj.update({
                    username: '123'
                    ,title: 'xxx'
                });
            } else if(layEvent === 'LAYTABLE_TIPS'){
                layer.alert('Hi，头部工具栏扩展的右侧图标。');
            }
        });
    });
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看回复</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</body>
</html>
